﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Midgard
{
    class SoundsManager
    {

        Dictionary<String, SoundEffect> sounds;
        Dictionary<String, Song> music;

        float soundVolume;
        float musicVolume;
        //float pan;
        //float fade;

        public Dictionary<String, SoundEffect> Sounds
        {
            get { return sounds; }
        }
        public Dictionary<String, Song> Music
        {
            get { return music; }
        }

        public float SoundVolume
        {
            get { return soundVolume; }
            set { soundVolume = SoundVolume; }
        }
        public float MusicVolume
        {
            get { return musicVolume; }
            set { musicVolume = MusicVolume; }
        }

        //public SoundEffect fireSound; // The sound that a projectile is fired. 

        //public SoundEffect explosionSound;  // The sound used when the player or an enemy dies
        //public Song MenuMusic;
        //public Song gameplayMusic; // The music played during gameplay
        //public Song forThor;
        //public SoundEffect serpentfx;
        //public SoundEffect thunder;


        // Load the music
        //public void loadSounds(Song gameMusic, SoundEffect fireSound, SoundEffect explosionSound, Song ForThor, Song serpentInjure, Song Thunder, Song NorseForce)
        //{
        //    MenuMusic = gameMusic;
        //    gameplayMusic = NorseForce;//Content.Load<Song>("sound/gameMusic");
        //    forThor = ForThor;
        //    this.fireSound = fireSound;
        //    this.explosionSound = explosionSound;
        //  //  explosionSound = Content.Load<SoundEffect>("sound/explosion");

        //    // Start the music right away
        //    PlayMusic(gameplayMusic);
        //}

        public SoundsManager(Dictionary<String, SoundEffect> Sounds, Dictionary<String, Song> Music)
        {
            sounds = Sounds;
            music = Music;
            soundVolume = .5f;
            musicVolume = .7f;

        }


        public void PlayMusic(String song)
        {
            try
            {
                // Play the music
                MediaPlayer.Stop();
                MediaPlayer.Play(music[song]);

                // Loop the currently playing song
                MediaPlayer.IsRepeating = true;
            }
            catch { }
        }

        public void PlaySound(String sound)
        {
            sounds[sound].Play(soundVolume,0f,0f);
        }
        public void PlaySound(String sound, float pan)
        {
            pan = Math.Max(-1, pan);
            pan = Math.Min(1, pan);
            sounds[sound].Play(soundVolume, 0f, pan);
        }
    }
}
